package com.fanli.staff.controller;

import com.fanli.staff.Service.SatffService;
import com.fanli.staff.config.Result;
import com.fanli.staff.pojo.Staff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
public class StaffController {
    @Autowired
    private SatffService service;

    @GetMapping("/selectAll")
    public Result selectAll(){
        List<Staff> staff = service.selectAll();
        System.out.println(staff);
        Result result = new Result(200, "查询成功",staff);
        System.out.println(result);
        return result;
    }
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable("id") Integer id){
        Staff staff = service.selectById(id);
        return new Result(200,"查询成功",staff);
    }
    @PostMapping("save")
    public Result save(@RequestBody Staff staff){
        service.save(staff);
        return new Result(200,"保存成功");
    }
    @PutMapping("update")
    public Result update(@RequestBody Staff staff){
        service.update(staff);
        return new Result(200,"更新成功");
    }
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
        service.delete(id);
        return new Result(200,"删除成功");
    }
}
